package com.soft.bams.entity;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/5/1
 */
public class LoanCreditAccount extends CreditAccount implements Loanable{

    //记录贷款金额
    private long loanAmount;


    @Override
    public Account requestLoan(double money) {
        if(money<=0){
            System.out.println("贷款金额必须>0");
            return this;
        }
        this.loanAmount+=money;
        this.setBalance(this.getBalance() + money);
        return this;
    }


    @Override
    public Account payLoan(double money) {
        if(money<=0){
            System.out.println("还款金额必须>0");
            return this;
        }
        if(money>loanAmount){
            System.out.println("还多了");
            return this;
        }

        if(this.getBalance() + this.getCeiling() >= money){
            if(this.getBalance()>=money){

                this.loanAmount-=money;
                this.setBalance(this.getBalance() - money);
            }else{

                this.loanAmount-=money;

                this.setCeiling(this.getCeiling() - (money - this.getBalance()));

                this.setBalance(0.0);
            }
        }else {
            System.out.println("您的余额不够支付还款");
        }
        return this;
    }

    public LoanCreditAccount() {

    }

    public LoanCreditAccount(String password, String name, String personId, String email, double balance, double ceiling, long loanAmount) {
        super(password, name, personId, email, balance, ceiling);
        this.loanAmount = loanAmount;
    }

    public LoanCreditAccount(Long id, String password, String name, String personId, String email, double balance, double ceiling, long loanAmount) {
        super(id, password, name, personId, email, balance, ceiling);
        this.loanAmount = loanAmount;
    }

    public long getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(long loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public String toString() {
        return "LoanCreditAccount{" +
                "loanAmount=" + loanAmount +
                "} " + super.toString();
    }
}